package com.lzl.netty.client.handler;

import cn.hutool.core.date.DateUtil;
import com.lzl.netty.client.protobuf.MsgPro;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext;
import sun.security.jca.GetInstance;

import java.util.Date;


public class UserHandler extends ChannelHandlerAdapter {


    /**
     * 当客户端与服务器建立连接成功后
     * @param ctx
     * @throws Exception
     */
    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        MsgPro.UserMsg.Builder builder = MsgPro.UserMsg.newBuilder();
        builder.setMsg("请给我钱");
        ctx.writeAndFlush(builder);
    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        if (msg!=null){
            MsgPro.UserMsg userMsg=(MsgPro.UserMsg)msg;
            System.out.println(userMsg.getMsg());
        }
    }



}
